package exam.bak.meituan;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class P5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine().trim());
        int[] nums = Arrays.stream(scanner.nextLine().trim().split(" ")).mapToInt(s -> Integer.parseInt(s)).toArray();
        System.out.println(solve(nums));
    }


    public static int solve(int[] nums) {
        int total = 0;
        int min = nums[0], max = nums[0];
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > min) {
                max = nums[i];
            } else if (nums[i] < min) {
                min = nums[i];
            }
        }
        Set<Integer> numSet = new HashSet<>();
        numSet.add(min);
        numSet.add(max);
        for (int i = 2; i < nums.length; i++) {
            int num = nums[i];
            if (min <= num && num <= max) {
                numSet.add(num);
            } else if (numSet.size() == (max - min + 1)) {
                total += 1;
                //重启新区间
                if (i + 1 < nums.length) {
                    min = nums[i + 1];
                    max = nums[i + 1];
                    for (int x = i + 1; x < nums.length; x++) {
                        if (nums[x] > min) {
                            max = nums[x];
                        } else if (nums[x] < min) {
                            min = nums[x];
                        }
                    }
                    numSet.clear();
                    numSet.add(max);
                    numSet.add(min);
                } else {
                    break;
                }
            } else {
                if (num > max) {
                    max = num;
                } else if (num < min) {
                    min = num;
                }
                numSet.add(num);
            }
        }
        return total + 1;
    }
}

